package com.sky.mapper;

import com.sky.aop.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 说明：
 *
 * @author Az 2023年02月20日14:37
 * @version 1.0
 */
@Mapper
@Component
public interface DishMapper {

//    分页查询
    List<DishVO> list(DishPageQueryDTO dishDTO);

//    新增菜品
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    @Insert("Insert into dish (name, category_Id, price, image, description, status ) " +
            "values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status})")
    void SaveDish(DishDTO dish);

//    根据id查询菜品
    @Select("select * from dish where id = #{id}")
    Dish selectById(Long id);


//    根据分类id查询菜品
    @Select("select * from dish where category_Id = #{categoryId}")
    List<Dish> selectByCateId(Long categoryId);


//    菜品起售、停售
    @Update("update dish set status = #{status} where id =#{id}")
    Integer updateStatus(Long id,Integer status);

    //修改
    @AutoFill(OperationType.UPDATE)
    @Update("update dish set name = #{name}, category_Id =#{categoryId},price = #{price}, image = #{image}, description= #{description}, " +
            "update_time =#{updateTime}, update_user=#{updateUser} where id= #{id} ")
    void updateById(Dish dish);


//  菜品删除
    @Delete(" delete from dish where id = #{id}")
    void removeById(Long  id);

    @Select("select * from dish")
    List<Dish> selectAllDish();

    //
    @Select("select * from dish")
    List<DishItemVO> selectAllDishItemVO();


    List<Dish> selectByIds(List<Long> ids);

    Integer countByMap(Map map);

//添加购物车新方法
    @Select("select * from dish where id = #{id}")
    Dish selectDishById(Long dishId);
}
